home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Inspectors / date.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  3.7 KB  |  129 lines

  1. // ******************** GLOBALS ****************************
  2.  
  3. var helpDoc = MM.HELP_inspDate;
  4.  
  5. // ******************** API ****************************
  6.  
  7. function canInspectSelection() {   
  8.     var lockObj = getSelectedObj();
  9.     if (lockObj.type && lockObj.type == "mmdate")
  10.        return true;
  11.     return false;
  12.  
  13.  
  14.  
  15. // ******************** API ****************************
  16.  
  17. //function: editDateFormat
  18. //description: called from Edit button, brings up original date command
  19. //dialog so that format can be edited
  20.  
  21. function editDateFormat(){
  22.    var lockObj = getSelectedObj();
  23.    var origFormat = lockObj.format;
  24.    var dateInfoArr = decipherDateID(origFormat);
  25.    
  26.    var dayFormat = dateInfoArr[0];
  27.    var dateFormat = dateInfoArr[1];
  28.    var timeFormat = dateInfoArr[2];
  29.    
  30.    //pop up date dialog and return the date string and date ID
  31.    var dateDialogArr= showDateDialog(dayFormat,dateFormat,timeFormat)
  32.    
  33.    //if user clicks Cancel from Date dialog, return
  34.    if (!dateDialogArr[0])
  35.       return;
  36.       
  37.    var newDateStr = dateDialogArr[0];
  38.    var newFormat  = dateDialogArr[1];
  39.    
  40.    //if nothing has changed, return
  41.    if (origFormat == newFormat)
  42.       return;
  43.    
  44.    dreamweaver.editLockedRegions(lockObj);
  45.    
  46.    //set orig and format attribute of lock object
  47.    var openComment = '%3C%21-- #BeginDate format:' + newFormat + ' --%3E';
  48.    var closeComment = '%3C%21-- #EndDate --%3E';
  49.    lockObj.orig = openComment + newDateStr + closeComment
  50.    lockObj.format = newFormat;
  51.    
  52.    //change text inside of the lock tags to be the new date
  53.    var lockParent = lockObj.parentNode;
  54.    var children = lockParent.childNodes;
  55.    var textNode;
  56.    for (var i=0;i<children.length;i++){
  57.       if (children.item(i) == lockObj)
  58.          textNode = children.item(i+1);
  59.    }
  60.    textNode.data = newDateStr;
  61.    
  62.    //select the date we've just edited
  63.    selArr = dreamweaver.nodeToOffsets(lockObj);
  64.    dreamweaver.setSelection(selArr[0],selArr[1]);  
  65.  
  66. }
  67.  
  68.  
  69.  
  70. //function: showDateDialog
  71. //description: displays the date dialog
  72. //returns an array of two items:
  73. //1.a date string using the chosen format
  74. //2.a date ID which shows the type of format, e.g.: "fcAm1"
  75. //means a full day, followed by a comma, followed by the American 1 format
  76.  
  77. function showDateDialog(dayFormat,dateFormat,timeFormat){
  78.    var cmdFile = dreamweaver.getConfigurationPath() + "/Commands/Date.htm";
  79.    var cmdDOM = dreamweaver.getDocumentDOM(cmdFile);
  80.    var cmdWin = cmdDOM.parentWindow;
  81.    
  82.    var theForm = cmdDOM.forms[0];
  83.    var dayMenu = theForm.DayFormats;
  84.    var dateMenu = theForm.DateFormats;
  85.    var timeMenu = theForm.TimeFormats;
  86.    
  87.    //popup the date window, but first -- remove the "Update Automatically" option
  88.    //and change title to be "Edit Date Format"
  89.    cmdDOM.getElementsByTagName("mmtag").item(0).innerHTML = "";
  90.    cmdDOM.getElementsByTagName("title").item(0).innerHTML = TITLE_EditDateFormat;
  91.    
  92.    //next, select the correct day format, date format, and time format.
  93.    cmdWin.initializeUI(); //populate the menus
  94.    selectMenuOption(dayMenu,"value",dayFormat); 
  95.    selectMenuOption(dateMenu,"value",dateFormat);
  96.    selectMenuOption(timeMenu,"value",timeFormat);
  97.    
  98.    dreamweaver.popupCommand("Date.htm");
  99.    
  100.    return new Array(   cmdWin.getDateStr(),
  101.                        cmdWin.getDateID()   );
  102. }
  103.  
  104.  
  105.  
  106. //function: selectMenuOption
  107. //description: given a select widget object, attribute, and value,
  108. //selects the option where attribute=value
  109. //for instance, given selObj,text,"my field", selects the option
  110. //with text equalling "my field"
  111.  
  112. function selectMenuOption(selObj,attr,val){
  113.    
  114.    var selInd = -1;
  115.    for (var i=0;i<selObj.options.length;i++){
  116.    
  117.       if ( selObj.options[i][attr] == [val]){
  118.          selInd = i;
  119.          break; 
  120.       }
  121.    }   
  122.    if (selInd!=-1)
  123.       selObj.selectedIndex = selInd;
  124.       
  125. }
  126.  
  127.  
  128.